# CodeName：generic_liutao
# Authon：liutao
# E-Mail：wxyj3496@126.com
# Creat time：2020-07-21
# Last Modified by:liutao
# Last Modified Time:2021-10-30
# futction：efine the generic function of liutao
# Version : V1.0
# is_number : Determine whether the string is a number

import re


def is_number(num):
    #pattern = re.compile(r'^[-+]?[-0-9]\d*\.\d*|[-+]?\.?[0-9]\d*$')原始的，两个连续小数点识别为真，前后单独都为假
    #pattern = re.compile(r'^[-+]?[-0-9]\d*\.\d*|[-+]?[0-9]\d*$')将第二项的.?去掉，情况依旧
    pattern = re.compile(r'^[-+]?\d*\.?\d*$') #这个可以，识别出连续小数点为假
    result = pattern.match(num)

    if result:
        return True
    else:
        return False


def main():
    a = is_number('a')
    b = is_number('2.1')
    print(a)
    print(b)


if __name__ == '__main__':
    main()
